<template>
	<div>
		<el-descriptions class="margin-top" :column="2">
			<template v-slot:title>
				<p>
					<strong class="mr8">{{ nowRowData.taskName }}</strong>
					<small>{{ nowRowData.status == 1 ? '已评估' : '未评估' }}</small>
				</p>
			</template>
			<el-descriptions-item label="隐患评估表">{{ nowRowData.tableTemplateName }}</el-descriptions-item>
			<el-descriptions-item label="评估结果">{{ nowRowData.result }}</el-descriptions-item>
			<el-descriptions-item label="评估第三方">{{ nowRowData.evaluateThirdParties }}</el-descriptions-item>
			<el-descriptions-item label="有效时间">{{ nowRowData.effectiveStartTime }}~{{ nowRowData.effectiveEndTime }}</el-descriptions-item>
		</el-descriptions>
		<p>
			<strong class="mr8 f16">任务表</strong>
		</p>
		<DetailPage class="detail-content" :model="formModel" v-if="!loading" v-bind="formConfig"></DetailPage>
	</div>
</template>

<script setup lang="ts">
import apiMod from '@/apiMod/index'
import DetailPage from '@/views/aplid/DetailPage/index.vue'

const props = defineProps<{
	nowRowData: any
}>()
const emit = defineEmits(['refresh'])

const formModel: any = ref({})

const formConfig = ref({
	inline: false,
	showBtn: true,
	labelPosition: 'top',
	labelWidth: '0',
	column: [],
})

const loading = ref(false)

const getInitData = () => {
	loading.value = true
	apiMod
		.view_tableItem_list({
			fieldId: props.nowRowData.id,
			tableTemplateId: props.nowRowData.tableTemplateId,
		})
		.then((res) => {
			if (res.data.length == 1) {
				const item = res.data[0] || {}
				formModel.value = JSON.parse(item.itemData)
				formModel.value.id = item.id
			}
		})

	apiMod
		.view_tableTemplate_id(props.nowRowData.tableTemplateId)
		.then((res) => {
			loading.value = false
			const config = res.data?.jsonStr || {}
			formConfig.value.column = config.column
			formConfig.value.labelPosition = config.labelPosition
		})
		.catch(() => {
			loading.value = false
		})
}

onMounted(() => {
	getInitData()
})
</script>

<style scoped lang="scss">
.detail-content {
	background: #f5f5f5d6;
	padding: 10px;
	margin: 10px 0;
	border-radius: 5px;
}
</style>
